package com.taotao.manage.controller.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.taotao.manage.pojo.Item;
import com.taotao.manage.service.ItemService;

/**
 *	提供给前台taotao-web的商品数据的api接口 
 */

/**
 * @Description:  
 * 		请求路径：api/item GET
 * 		请求参数：itemId
 * 		结果响应：Item
 * @author:     mingxu
 */
@RequestMapping(value = "api/item")
@Controller
public class ApiItemController {

	@Autowired
	private ItemService itemService;

	/**
	 * @Description:根据商品id查询商品
	 * @param itemId
	 * @return
	 * @author mingxu
	 */
	@RequestMapping(value = "{itemId}", method = RequestMethod.GET)
	public ResponseEntity<Item> queryItemById(@PathVariable("itemId") Long itemId) {

		try {
			Item item = itemService.queryItemById(itemId);
			return ResponseEntity.status(HttpStatus.OK).body(item);
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
		}

	}

}
